<template>
  <div class="auditList">
    <section class="header clearfix">
      <span>企业审核</span>
    </section>
    <ul class="menu-swtich clearfix">
      <li
        v-for="(item, index) in menu"
        :key="index"
        :class="[auditStatus == index ? 'active' : '']"
        @click="switchFun(index)"
      >
        {{ item.title }}
      </li>

    </ul>
    <div class="search-box" @keyup.enter="searchFun">
      <i class="iconfont iconsearch1"></i>
      <el-input
        placeholder="输入企业名称进行搜索"
        class="search"
        v-model.trim="companyName"
        clearable
      ></el-input>
    </div>
    <div class="search-box search-box-last">
      <section class="option">
        <span>审核类型:</span>
        <el-select
          v-model="auditType"
          clearable
          @change="getData"
          placeholder="请选择"
        >
          <el-option
            v-for="item in auditTypeLists"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </section>

    </div>
    <div class="table">
      <el-table
        ref="multipleTable"
        :data="auditList"
        v-loading="loading"
        tooltip-effect="dark"
        style="width: 100%"
      >
<!--         <el-table-column type="selection" width="55"> </el-table-column> -->
        <el-table-column
          prop="companyName"
          fixed
          label="企业名称"
        ></el-table-column>
        <el-table-column fixed label="类型">
          <template slot-scope="scope">
            {{ scope.row.auditType | auditTypeFilter }}
          </template>
        </el-table-column>
        <el-table-column
          prop="submitAuditTime"
          fixed
          label="提交时间"
        ></el-table-column>
        <el-table-column
          prop="auditStatus"
          label="审核结果"
          :formatter="auditStatusFormatter"
        ></el-table-column>
        <el-table-column
          label="审核不通过原因"
        >
          <template slot-scope="scope">
            {{scope.row.auditStatus=="2"?(scope.row.auditContent && JSON.parse(scope.row.auditContent)[JSON.parse(scope.row.auditContent).length-1].remark):""}}
          </template>

        </el-table-column>
        <el-table-column
          prop="content"
          label="说明"
        ></el-table-column>
        <el-table-column label="详情" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="look(scope.row.auditId,scope.row.companyId, scope.row.auditStatus)"
            >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="current"
        :page-sizes="[6, 12, 24, 36]"
        :page-size="pageSize"
        layout="sizes, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
    <el-drawer
      title="企业详情"
      :visible.sync="drawerAuditCompany"
      size="50%">
      <auditCompanyDetail :audit-id="dialogAuditId" :key="dialogAuditKey"></auditCompanyDetail>
      <div class="demo-drawer__footer" style="margin: 30px 0 10px 20px">
        <template v-if="dialogAuditStatus==0">
          <el-button type="primary" @click="processAudit(1)" :loading="loading">{{ loading ? '提交中 ...' : '审核通过' }}</el-button>
          <el-button type="primary" @click="processAudit(2)" :loading="loading">{{ loading ? '提交中 ...' : '审核不通过' }}</el-button>
        </template>
        <el-button @click="cancelForm">取 消</el-button>
      </div>
    </el-drawer>

    <el-dialog
      title="未通过审核原因"
      :visible.sync="dialogProcessMsgVisible"
      width="30%"
      :before-close="handleProcessMsgClose">
      <span><el-input placeholder="请输入未通过审核原因" v-model="dialogProcessMsg" clearable></el-input></span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogProcessMsgVisible = false">取 消</el-button>
    <el-button type="primary" @click="handleProcessMsgConfirm()">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  requestApiPost
} from "../api/api";
import { reqRep } from "../report/reqReport";
import { resRep } from "../report/resReport";
import JsonExcel from "vue-json-excel";
import base from "../assets/js/base";
import auditCompanyDetail from "./auditCompanyDetail.vue";
export default {
  name: "auditList",
  data() {
    return {
      drawerAuditCompany:false,
      dialogProcessMsgVisible:false,
      companyName:"",
      auditList:[],
      date: [],
      inOutJobStatus: "0",
      idCard: "",
      isDisabled: true,
      loading: false,
      outInutLoading: false,
      total: null,
      current: 1,
      pageSize: 6,
      menu: [
        { title: "未处理", value: "0" },
        { title: "已通过", value: "1" },
        { title: "未通过", value: "2" },
      ],
      auditType:"0",
      auditTypeLists:[
        {
          value:"0",
          label:"新增企业审核"
        },
        {
          value:"1",
          label:"修改企业审核"
        }
      ],
      platformOptions: [], //参保单位
      excelData: [],
      exportDataLoading: false,
      exportEmployeeLoading: false,
      dialogAuditId:"",
      dialogAuditStatus:0,
      dialogAuditKey:"",
      dialogCompanyId:"",
      dialogProcessMsg:"",
      auditStatus:0,
    };
  },
  methods: {
    handleCurrentChange(e) {
      this.current = e;
      this.getData();
    },
    handleSizeChange(e) {
      this.pageSize = e;
      this.getData();
    },
    handleProcessMsgClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    handleProcessMsgConfirm(){
      if(this.dialogProcessMsg===""){
        this.$message.error('请输入不通过审核信息');
        return;
      }
      this.dialogProcessMsgVisible=false;
      this.process(this.dialogAuditId,2,this.dialogProcessMsg,this.dialogCompanyId);
    },
    searchFun() {
      this.current = 1;
      this.auditList = [];
      this.getData();
    },
    look(auditId, companyId, auditStatus) {
      // this.$router.push({
      //   path: "/auditCompanyDetail",
      //   query: { auditId, auditType },
      // });
      this.dialogAuditKey=new Date().getTime();
      this.dialogAuditId=auditId;
      this.dialogCompanyId=companyId;
      this.dialogAuditStatus=auditStatus;
      this.drawerAuditCompany=true;
    },
    switchFun(i) {
      this.auditStatus = i;
      this.current = 1;
      this.getData();
    },
    processAudit(auditStatus){
      var msg="确认该企业"+(auditStatus=="1"?'审核通过':'审核不通过')+'？'
      this.$confirm(msg)
        .then(_ => {
          if(auditStatus==2){
            this.dialogProcessMsg="";
            this.dialogProcessMsgVisible=true;
            return;
          }
          this.process(this.dialogAuditId,auditStatus,this.dialogProcessMsg,this.dialogCompanyId)
        })
        .catch(_ => {});
    },
    process(auditId,auditStatus,msg,companyId){
      let reqData={auditId:auditId,processStatus:auditStatus,processMsg:msg,companyId:companyId};
      let reqReport = reqRep({ traCode: "_PROCESS_AUDIT_COMPANY", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        this.loading = false;
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.drawerAuditCompany=false;
          this.auditList = resReport.data.records;
          this.total = parseInt(resReport.data.total);
          // if (this.isProcess == "0") {
          //   this.$store.commit("changeAudit", this.total);
          // }
        }
      });
    },
    cancelForm(){
      this.drawerAuditCompany=false;
    },
    //获取数据
    getData() {
      this.loading = true;
      this.auditList = [];

      let submitTimeStart =
        this.date && this.date.length > 0 ? this.date[0] : "";
      let submitTimeEnd = this.date && this.date.length > 0 ? this.date[1] : "";

      var reqData = {
        companyName: this.companyName,
        auditType: this.auditType,
        auditStatus: this.auditStatus,
        current: this.current,
        pageSize: this.pageSize,
      };
      base.saveSearchCriteria(this.$route.path, reqData);
      let reqReport = reqRep({ traCode: "_LIST_AUDIT_COMPANY", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        this.loading = false;
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.auditList = resReport.data.records;
          this.total = parseInt(resReport.data.total);
          // if (this.isProcess == "0") {
          //   this.$store.commit("changeAudit", this.total);
          // }
        }
      });
    },
    //获取参保单位
    getPlatform() {
      var reqData = {
        current: 1,
        pageSize: 999,
      };
      let reqReport = reqRep({ traCode: "_LIST_PAY_PLATFORM", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.platformOptions = resReport.data.records;
          this.getData();
        }
      });
    },
    //审核结果 0未审核；1审核通过；2审核不通过
    auditStatusFormatter(a, b, c) {
      if (c == "0") {
        return "未审核";
      } else if (c == "1") {
        return "已通过";
      } else if (c == "2") {
        return "审核不通过";
      }
    },
  },
  filters: {
    //审核类型0入职审核；1离职审核；2停缴公积金审核；3减少缴纳项目；4增加缴纳项目
    auditTypeFilter(c) {
      if (c == 0) {
        return "新增企业审核";
      } else if (c == 1) {
        return "修改企业审核";
      }
    },
  },
  components: {
    auditCompanyDetail,
  },

  created() {
    //获取路由参数
    if (Object.keys(this.$route.query).length > 0) {
      let query = this.$route.query;
      let that = this;
      for (const key in query) {
        if (Object.hasOwnProperty.call(query, key)) {
          const element = query[key];
          if (key == "pageSize" || key == "current" || key == "platformId") {
            that[key] = base.strToNumber(element);
          } else if (key == "inOutJobStatus") {
            that[key] = String(element);
          } else {
            if (key == "submitTimeStart" || key == "submitTimeEnd") {
              if (key == "submitTimeStart" && element) {
                that.date.splice(0, 1, element);
              }
              if (key == "submitTimeEnd" && element) {
                that.date.splice(1, 1, element);
              }
            } else {
              that[key] = element;
            }
          }
        }
      }
    }
    this.getPlatform();
  },
};
</script>
<style scoped>
.header {
  padding: 15px;
  height: 50px;
  box-sizing: border-box;
  font-size: 14px;
  border-bottom: 1px solid #eee;
}
.header .org {
  float: right;
  cursor: pointer;
}
.org:hover {
  color: #13cb6e;
}
.header i {
  margin-right: 5px;
}
.opt-user {
  padding: 20px 15px;
}
.opt-user > section {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}
.opt-user i {
  font-size: 20px;
  margin-right: 5px;
  vertical-align: middle;
}
.opt-user .iconadd1 {
  color: #13cb6e;
}
.opt-user .iconbiaoge-xiazai {
  color: #33ac37;
}
.add-user:hover {
  color: #13cb6e;
}
.input-user:hover {
  color: #33ac37;
}
.menu-swtich {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eee;
}
.menu-swtich li {
  display: inline-block;
  padding: 0 15px;
  cursor: pointer;
}
.menu-swtich .el-button {
  margin-top: 5px;
  float: right;
  margin-right: 10px;
}

.active {
  color: #13cb6e;
  border-bottom: 2px solid #13cb6e;
}
.search-box {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eee;
}
.search-box-last {
  border-top: none;
}
.search-box i {
  margin-left: 15px;
  vertical-align: middle;
}
.search-box .search {
  display: inline-block;
  width: calc(100% - 36px);
}
.search-box .option {
  display: inline-block;
  margin-left: 15px;
}
.search-box .el-select {
  width: 150px;
}
.search-box .el-select input {
  min-width: 100px;
  background-color: #eee;
}
.search-box .batchChange {
  display: inline-block;
  color: #999;
  font-size: 14px;
  cursor: pointer;
}

.showMoney {
  padding: 15px;
}
.showMoney .sm-h {
  margin-bottom: 40px;
}
.sm-h section {
  display: inline-block;
  margin-right: 20px;
}
.sm-h .month {
  margin-left: 10px;
  color: #999;
}
i {
  color: #999;
  font-size: 16px;
}
.download {
  float: right;
  font-size: 14px;
  margin-right: 0 !important;
}
.sm-f > ul {
  display: inline-block;
  width: 100px;
  margin-right: 15px;
  color: #666;
}
.sm-f .value {
  color: #666;
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 5px;
}
.sm-f .button {
  float: right;
  width: 140px;
  text-align: center;
  height: 50px;
  font-size: 20px;
  line-height: 50px;
  color: #fff;
  border-radius: 4px;
  background-color: #13cb6e;
}
.table {
  margin-top: 4px;
}
.table .content {
  display: inline-block;
  border-right: 1px solid #ccc;
}
.table .content:last-child {
  border: none;
}
.table .content > section {
  padding: 10px 15px;
}
.table .content > section span {
  margin-right: 10px;
  display: inline-block;
  width: 80px;
  color: #999;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.table .content > section span:nth-child(2) {
  text-align: center;
}
.table .content > section span:last-child {
  margin-right: 0;
  text-align: center;
}
.rests {
  float: right;
}
</style>
